function refresh() {
    tableIn.reload('btable');
}

var tableIn = null;

$(function () {
    number('/commodity/number','#qb')
})

$(function () {
    number('/commodity/numberPayment','#dfk')
})

$(function () {
    number('/commodity/numberConsignment','#dfh')
})

$(function () {
    number('/commodity/numberShipped','#yfh')
})

$(function () {
    number('/commodity/numberSigned','#yqs')
})

$(function () {
    number('/refund/numberReturnRequest','#dth')
})

$(function () {
    number('/refund/numberReturned','#thz')
})

$(function () {
    number('/refund/numberReturning','#yth')
})

$(function () {
    number('/commodity/numberCancel','#yqx')
})

$(function () {
    number('/refund/numberReturnRequest','#jjth')
})

function number(a,b){
    $(function () {
        $.ajax({
            type:'get',
            url:a,
            success:function (res){
                $(b).text(res.state);
            }
        })
    })
}

layui.use(['table','form'], function () {
    var table = layui.table;
    var form = layui.form;

    tableIn = table.render({
        elem: '#ordertable',
        url: '/commodity/getConsignment',
        toolbar: true,
        id:'btable',
        page: {
            limit: 10,
            limits: [5, 10, 15],
            group: 10
        },
        cols: [
            [
                {field: "orderId", title: '序号'},
                {field: "orderNo", title: "订单编号"},
                {field: "userNickname", title: "用户昵称"},
                {field: "productName", title: "商品名称"},
                {field: "logisticsFee",title: "订单金额"},
                {field: "orderPaymentChannel", title: "支付方式",templet:function (d) {
                        if (d.orderPaymentChannel == 1){
                            return "未支付";
                        }if (d.orderPaymentChannel == 2){
                            return "微信支付";
                        }if (d.orderPaymentChannel == 3){
                            return "余额支付";
                        }if (d.orderPaymentChannel == 4){
                            return "支付宝支付";
                        }
                    }},
                {field: "orderSource", title: "订单来源",templet:function (d) {
                        if (d.orderSource == 1){
                            return "app";
                        }else {
                            return "小程序";
                        }
                    }},
                {field: "orderStatus", title: "订单状态",templet:function (d) {
                        if (d.orderStatus == 1){
                            return "已付款";
                        }if (d.orderStatus == 2){
                            return "待付款";
                        }if (d.orderStatus == 3){
                            return "待发货";
                        }if (d.orderStatus == 4){
                            return "已发货";
                        }if (d.orderStatus == 5){
                            return "已签收";
                        }if (d.orderStatus == 6){
                            return "退货申请";
                        }if (d.orderStatus == 7){
                            return "退货中";
                        }if (d.orderStatus == 8){
                            return "已退货";
                        }if (d.orderStatus == 9){
                            return "取消交易";
                        }if (d.orderStatus == 10){
                            return "拒绝退货";
                        }
                    }},
                {field: "createDate",title: "提交时间"},
                {toolbar:'#bardemo',title: "操作"}
            ]
        ],
        parseData: function (res) {
            return {
                "code": res.state,
                "msg": res.Message,
                "count": res.total,
                "data": res.data
            };
        },
    });


    form.on('submit(*)',function (d){
        d = d.field;
        console.log(d);
        table.reload('btable',{
            url: '/commodity/selectConsignment',
            where:{ // 设定异步数据接口的额外参数，任意设
                orderSource:d.quiz3,
                orderStatus:d.quiz2,
                orderPaymentChannel:d.quiz1
            },
            page: {
                page:1,//重新从第一页开始
                limit: 10
            },

        })

    })

    table.on("tool(equip)", function (obj) {
        var event = obj.event;

        if (event === 'ck') {
            layer.open({
                type: 2,
                title: "课程订单详情",
                content: "ck.html",
                area: ['100%', '100%'],
                success: function (layero, index) {

                    let childFrame = layer.getChildFrame('body', index);

                    childFrame.find('input[name=orderNo]').val(obj.data.orderNo);
                    childFrame.find('input[name=courseName]').val(obj.data.courseName);
                    childFrame.find('input[name=orderStatus]').val(obj.data.orderStatus);
                    childFrame.find('input[name=orderPaymentChannel]').val(obj.data.orderPaymentChannel);
                    childFrame.find('input[name=orderSource]').val(obj.data.orderSource);
                    childFrame.find('input[name=orderType]').val(obj.data.orderType);
                    childFrame.find('input[name=name]').val(obj.data.name);
                    childFrame.find('input[name=userNickname]').val(obj.data.userNickname);

                    if (obj.data.orderPaymentChannel == 1){
                        childFrame.find('input[name=orderPaymentChannel]').val("未支付");
                    }if (obj.data.orderPaymentChannel == 2){
                        childFrame.find('input[name=orderPaymentChannel]').val("微信支付");
                    }if (obj.data.orderPaymentChannel == 3){
                        childFrame.find('input[name=orderPaymentChannel]').val("余额支付");
                    }if (obj.data.orderPaymentChannel == 4){
                        childFrame.find('input[name=orderPaymentChannel]').val("支付宝支付");
                    }

                    if (obj.data.orderSource == 1) {
                        childFrame.find('input[name=orderSource]').val('app');
                    } else {
                        childFrame.find('input[name=orderSource]').val('小程序');
                    };

                    if (obj.data.orderStatus == 1){
                        childFrame.find('button[id=btn3]').css("display","none");
                        childFrame.find('button[id=btn4]').css("display","none");
                        childFrame.find('input[name=orderStatus]').val('已付款');
                    }if (obj.data.orderStatus == 2){
                        childFrame.find('button[id=btn3]').css("display","none");
                        childFrame.find('button[id=btn4]').css("display","none");
                        childFrame.find('input[name=orderStatus]').val('待付款');
                    }if (obj.data.orderStatus == 3){
                        childFrame.find('input[name=orderStatus]').val('待发货');
                    }if (obj.data.orderStatus == 4){
                        childFrame.find('button[id=btn3]').css("display","none");
                        childFrame.find('button[id=btn4]').css("display","none");
                        childFrame.find('input[name=orderStatus]').val('已发货');
                    }if (obj.data.orderStatus == 5){
                        childFrame.find('button[id=btn3]').css("display","none");
                        childFrame.find('button[id=btn4]').css("display","none");
                        childFrame.find('input[name=orderStatus]').val('已签收');
                    }if (obj.data.orderStatus == 6){
                        childFrame.find('button[id=btn3]').css("display","none");
                        childFrame.find('button[id=btn4]').css("display","none");
                        childFrame.find('input[name=orderStatus]').val('退货申请');
                    }if (obj.data.orderStatus == 7){
                        childFrame.find('button[id=btn3]').css("display","none");
                        childFrame.find('button[id=btn4]').css("display","none");
                        childFrame.find('input[name=orderStatus]').val('退货中');
                    }if (obj.data.orderStatus == 8){
                        childFrame.find('button[id=btn3]').css("display","none");
                        childFrame.find('button[id=btn4]').css("display","none");
                        childFrame.find('input[name=orderStatus]').val('已退货');
                    }if (obj.data.orderStatus == 9){
                        childFrame.find('button[id=btn3]').css("display","none");
                        childFrame.find('button[id=btn4]').css("display","none");
                        childFrame.find('input[name=orderStatus]').val('取消交易');
                    }if (obj.data.orderStatus == 10){
                        childFrame.find('button[id=btn3]').css("display","none");
                        childFrame.find('button[id=btn4]').css("display","none");
                        childFrame.find('input[name=orderStatus]').val('拒绝退货');
                    }

                    if (obj.data.orderType == 1){
                        childFrame.find('input[name=orderType]').val("视频");
                    }else {
                        childFrame.find('input[name=orderType]').val("商品");
                    }
                }
            })
        }
    })

});

function qb(){
    jo('/commodity/get','/commodity/select');
}

function dfk(){
    jo('/commodity/getPayment','/commodity/selectPayment');
}

function dfh(){
    jo('/commodity/getConsignment','/commodity/selectConsignment');
}

function yfh(){
    jo('/commodity/getShipped','/commodity/selectShipped');
}

function yqs(){
    jo('/commodity/getSigned','/commodity/selectSigned');
}

function yqx(){
    jo('/commodity/getCancel','/commodity/selectCancel');
}

function dth(){
    jo('/refund/getReturnRequest','/refund/selectReturnRequest');
}

function thz(){
    jo('/refund/getReturnRequest','/refund/selectReturnRequest');
}

function yth(){
    jo('/refund/getReturning','/refund/selectReturning');
}

function jjth(){
    jo('/refund/getRefuse','/refund/selectRefuse');
}


function jo(a,b){
    layui.use(['table','form'], function () {
        var table = layui.table;
        var form = layui.form;

        tableIn = table.render({
            elem: '#ordertable',
            url: a,
            toolbar: true,
            id:'btable',
            page: {
                limit: 10,
                limits: [5, 10, 15],
                group: 10
            },
            cols: [
                [
                    {field: "orderId", title: '序号'},
                    {field: "orderNo", title: "订单编号"},
                    {field: "userNickname", title: "用户昵称"},
                    {field: "productName", title: "商品名称"},
                    {field: "logisticsFee",title: "订单金额"},
                    {field: "orderPaymentChannel", title: "支付方式",templet:function (d) {
                            if (d.orderPaymentChannel == 1){
                                return "未支付";
                            }if (d.orderPaymentChannel == 2){
                                return "微信支付";
                            }if (d.orderPaymentChannel == 3){
                                return "余额支付";
                            }if (d.orderPaymentChannel == 4){
                                return "支付宝支付";
                            }
                        }},
                    {field: "orderSource", title: "订单来源",templet:function (d) {
                            if (d.orderSource == 1){
                                return "app";
                            }else {
                                return "小程序";
                            }
                        }},
                    {field: "orderStatus", title: "订单状态",templet:function (d) {
                            if (d.orderStatus == 1){
                                return "已付款";
                            }if (d.orderStatus == 2){
                                return "待付款";
                            }if (d.orderStatus == 3){
                                return "待发货";
                            }if (d.orderStatus == 4){
                                return "已发货";
                            }if (d.orderStatus == 5){
                                return "已签收";
                            }if (d.orderStatus == 6){
                                return "退货申请";
                            }if (d.orderStatus == 7){
                                return "退货中";
                            }if (d.orderStatus == 8){
                                return "已退货";
                            }if (d.orderStatus == 9){
                                return "取消交易";
                            }if (d.orderStatus == 10){
                                return "拒绝退货";
                            }
                        }},
                    {field: "createDate",title: "提交时间"},
                    {toolbar:'#bardemo',title: "操作"}
                ]
            ],
            parseData: function (res) {
                return {
                    "code": res.state,
                    "msg": res.Message,
                    "count": res.total,
                    "data": res.data
                };
            },
        });


        form.on('submit(*)',function (d){
            d = d.field;
            console.log(d);
            table.reload('btable',{
                url: b,
                where:{ // 设定异步数据接口的额外参数，任意设
                    orderSource:d.quiz3,
                    orderStatus:d.quiz2,
                    orderPaymentChannel:d.quiz1
                },
                page: {
                    page:1,//重新从第一页开始
                    limit: 10
                },

            })

        })

        table.on("tool(equip)", function (obj) {
            var event = obj.event;

            if (event === 'ck') {
                layer.open({
                    type: 2,
                    title: "课程订单详情",
                    content: "ck.html",
                    area: ['100%', '100%'],
                    success: function (layero, index) {

                        let childFrame = layer.getChildFrame('body', index);

                        childFrame.find('input[name=orderNo]').val(obj.data.orderNo);
                        childFrame.find('input[name=courseName]').val(obj.data.courseName);
                        childFrame.find('input[name=orderStatus]').val(obj.data.orderStatus);
                        childFrame.find('input[name=orderPaymentChannel]').val(obj.data.orderPaymentChannel);
                        childFrame.find('input[name=orderSource]').val(obj.data.orderSource);
                        childFrame.find('input[name=orderType]').val(obj.data.orderType);
                        childFrame.find('input[name=name]').val(obj.data.name);
                        childFrame.find('input[name=userNickname]').val(obj.data.userNickname);
                        childFrame.find('input[name=userAccount]').val(obj.data.userAccount);
                        childFrame.find('input[name=phone]').val(obj.data.phone);
                        childFrame.find('input[name=receivingAddress]').val(obj.data.receivingAddress);
                        childFrame.find('img[name=mainImage]').attr("src",obj.data.mainImage);
                        childFrame.find('input[name=productName]').val(obj.data.productName);
                        childFrame.find('input[name=productCode]').val(obj.data.productCode);
                        childFrame.find('input[name=currentpriceProduct]').val(obj.data.currentpriceProduct);
                        childFrame.find('input[name=receiverUser]').val(obj.data.receiverUser);


                        if (obj.data.orderPaymentChannel == 1){
                            childFrame.find('input[name=orderPaymentChannel]').val("未支付");
                        }if (obj.data.orderPaymentChannel == 2){
                            childFrame.find('input[name=orderPaymentChannel]').val("微信支付");
                        }if (obj.data.orderPaymentChannel == 3){
                            childFrame.find('input[name=orderPaymentChannel]').val("余额支付");
                        }if (obj.data.orderPaymentChannel == 4){
                            childFrame.find('input[name=orderPaymentChannel]').val("支付宝支付");
                        }

                        if (obj.data.orderSource == 1) {
                            childFrame.find('input[name=orderSource]').val('app');
                        } else {
                            childFrame.find('input[name=orderSource]').val('小程序');
                        };

                        if (obj.data.orderStatus == 1){
                            childFrame.find('button[id=btn3]').css("display","none");
                            childFrame.find('button[id=btn4]').css("display","none");
                            childFrame.find('input[name=orderStatus]').val('已付款');
                        }if (obj.data.orderStatus == 2){
                            childFrame.find('button[id=btn3]').css("display","none");
                            childFrame.find('button[id=btn4]').css("display","none");
                            childFrame.find('input[name=orderStatus]').val('待付款');
                        }if (obj.data.orderStatus == 3){
                            childFrame.find('input[name=orderStatus]').val('待发货');
                        }if (obj.data.orderStatus == 4){
                            childFrame.find('button[id=btn3]').css("display","none");
                            childFrame.find('button[id=btn4]').css("display","none");
                            childFrame.find('input[name=orderStatus]').val('已发货');
                        }if (obj.data.orderStatus == 5){
                            childFrame.find('button[id=btn3]').css("display","none");
                            childFrame.find('button[id=btn4]').css("display","none");
                            childFrame.find('input[name=orderStatus]').val('已签收');
                        }if (obj.data.orderStatus == 6){
                            childFrame.find('button[id=btn3]').css("display","none");
                            childFrame.find('button[id=btn4]').css("display","none");
                            childFrame.find('input[name=orderStatus]').val('退货申请');
                        }if (obj.data.orderStatus == 7){
                            childFrame.find('button[id=btn3]').css("display","none");
                            childFrame.find('button[id=btn4]').css("display","none");
                            childFrame.find('input[name=orderStatus]').val('退货中');
                        }if (obj.data.orderStatus == 8){
                            childFrame.find('button[id=btn3]').css("display","none");
                            childFrame.find('button[id=btn4]').css("display","none");
                            childFrame.find('input[name=orderStatus]').val('已退货');
                        }if (obj.data.orderStatus == 9){
                            childFrame.find('button[id=btn3]').css("display","none");
                            childFrame.find('button[id=btn4]').css("display","none");
                            childFrame.find('input[name=orderStatus]').val('取消交易');
                        }if (obj.data.orderStatus == 10){
                            childFrame.find('button[id=btn3]').css("display","none");
                            childFrame.find('button[id=btn4]').css("display","none");
                            childFrame.find('input[name=orderStatus]').val('拒绝退货');
                        }

                        if (obj.data.orderType == 1){
                            childFrame.find('input[name=orderType]').val("视频");
                        }else {
                            childFrame.find('input[name=orderType]').val("商品");
                        }
                    }
                })
            }
        })

    });
}

$(document).on("click","button",function(){
    $(".layui-btn-primary").each(function(n,value){
        $(value).removeClass("check");
    });
    $(this).addClass("check");
});